package com.study.wechatboot.autoreply.controller;

import com.study.wechatboot.autoreply.pojo.recvmsg.RecvMsgJson;
import com.study.wechatboot.autoreply.service.impl.RecvMsgServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wechatboot")
public class RecvMsgJsonParsingController {

    public RecvMsgJsonParsingController(RecvMsgServiceImpl recvMsgService) {
        this.recvMsgService = recvMsgService;
    }

    @PostMapping("/callback")
    public ResponseEntity<String> receiveMessage(@RequestBody String requestBody) {
        // 这里可以打印请求体，用于调试
        System.out.println("Received message: " + requestBody);
        // 假设我们只是返回一个简单的确认
        return ResponseEntity.ok("Received");
    }

    private final RecvMsgServiceImpl recvMsgService;

    @PostMapping("/parseJson")
    public String parseJson(@RequestBody RecvMsgJson recvMsgJson) {
        String messageType = recvMsgService.processFromType(recvMsgJson);
        System.out.println("消息类型: " + messageType);
        return "获取成功";
    }
}
